package com.jms.web.controller.jms.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.jms.common.filter.utils.poi.ExcelUtil;
import com.jms.web.controller.jms.domain.News;
import com.jms.web.controller.jms.service.INewsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jms.common.annotation.Log;
import com.jms.common.core.controller.BaseController;
import com.jms.common.core.domain.AjaxResult;
import com.jms.common.enums.BusinessType;
import com.jms.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 资讯详情Controller
 * 
 * @author drx
 * @date 2024-04-29
 */
@RestController
@RequestMapping("/system/news")
public class NewsController extends BaseController
{
    @Resource
    private INewsService newsService;

    /**
     * 查询资讯详情列表
     */
    @PreAuthorize("@ss.hasPermi('system:news:list')")
    @GetMapping("/list")
    public TableDataInfo list(News news)
    {
        startPage();
        List<News> list = newsService.selectNewsList(news);
        return getDataTable(list);
    }

    /**
     * 查询资讯详情列表
     */
    @PreAuthorize("@ss.hasPermi('system:news:list')")
    @PostMapping("/getList")
    public TableDataInfo getList(@RequestBody News news)
    {
        startPage();
        List<News> list = newsService.selectNewsList(news);
        return getDataTable(list);
    }

    /**
     * 导出资讯详情列表
     */
    @PreAuthorize("@ss.hasPermi('system:news:export')")
    @Log(title = "资讯详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, News news)
    {
        List<News> list = newsService.selectNewsList(news);
        ExcelUtil<News> util = new ExcelUtil<News>(News.class);
        util.exportExcel(response, list, "资讯详情数据");
    }

    /**
     * 获取资讯详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:news:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(newsService.selectNewsById(id));
    }

    /**
     * 新增资讯详情
     */
    @PreAuthorize("@ss.hasPermi('system:news:add')")
    @Log(title = "资讯详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody News news)
    {
        return toAjax(newsService.insertNews(news));
    }

    /**
     * 修改资讯详情
     */
    @PreAuthorize("@ss.hasPermi('system:news:edit')")
    @Log(title = "资讯详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody News news)
    {
        return toAjax(newsService.updateNews(news));
    }

    /**
     * 删除资讯详情
     */
    @PreAuthorize("@ss.hasPermi('system:news:remove')")
    @Log(title = "资讯详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(newsService.deleteNewsByIds(ids));
    }
}
